package com.ld.control.business.task.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ld.control.business.task.service.TaskExampleService;
import com.ld.control.business.task.service.TaskTmpService;
import com.ld.control.business.task.vo.req.ConfigProcessTmpReqVo;
import com.ld.control.business.task.vo.req.TaskExampleReqVo;
import com.ld.control.business.task.vo.req.TaskExampleSearchReqVo;
import com.ld.control.business.task.vo.req.TaskTmpReqVo;
import com.ld.control.business.task.vo.resp.TaskExampleRespVo;
import com.ld.control.business.task.vo.resp.TaskTmpRespVo;
import com.ld.control.common.ResultResponse;
import com.ld.control.common.vo.GenerateListVo;
import com.ld.control.common.vo.GeneratePageListVo;
import com.ld.control.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 任务模板表 前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2024-05-09
 */
@Slf4j
@Tag(name = "任务实例相关接口")
@RestController
public class TaskExampleController {

    @Autowired
    private TaskExampleService taskExampleService;

    @PostMapping("/api/centralControl/taskExample/add")
    @Operation(summary = "添加任务实例")
    public ResultResponse<ResultResponseEnum> add(
            @RequestBody TaskExampleReqVo reqVo
    ) {
        taskExampleService.add(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/taskExample/getPageList")
    @Operation(summary = "任务实例列表")
    public ResultResponse<GeneratePageListVo<TaskExampleRespVo>> getPageList(
            @RequestBody TaskExampleSearchReqVo reqVo
    ) {
        IPage<TaskExampleRespVo> pageList = taskExampleService.getPageList(reqVo);
        return ResultResponse.success(new GeneratePageListVo<>(pageList));
    }

    @PostMapping("/api/centralControl/taskExample/run")
    @Operation(summary = "运行任务实例")
    public ResultResponse<ResultResponseEnum> runTaskExample(
            @RequestParam Long id
    ) {
        taskExampleService.runTaskExample(id);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/taskExample/pause")
    @Operation(summary = "暂停")
    public ResultResponse<ResultResponseEnum> pause(
            @RequestParam Long id
    ) {
        taskExampleService.pause(id);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/taskExample/restore")
    @Operation(summary = "恢复")
    public ResultResponse<ResultResponseEnum> restore(
            @RequestParam Long id
    ) {
        taskExampleService.restore(id);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/taskExample/termination")
    @Operation(summary = "终止任务")
    public ResultResponse<ResultResponseEnum> termination(
            @RequestParam Long id
    ) {
        taskExampleService.termination(id);
        return ResultResponse.success();
    }

    @GetMapping("/api/centralControl/taskExample/getTaskDataSelectList")
    @Operation(summary = "数据样品管理页面 任务下拉框")
    public ResultResponse<GenerateListVo<TaskExampleRespVo>> getTaskDataSelectList() {
        return ResultResponse.success(new GenerateListVo<>(taskExampleService.getTaskDataSelectList()));
    }


}

